package com.top.ruizhong.main.host

import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.ConvertUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.module.lemlin.base.BaseAbstractFragment
import com.module.lemlin.custom.SpacingItemDecoration
import com.top.ruizhong.R
import com.top.ruizhong.main.order.OrderDetailsActivity
import kotlinx.android.synthetic.main.fragment_main_order.*

class MainOrderFragment : BaseAbstractFragment() {


    companion object {
        fun newInstance(): MainOrderFragment {
            return MainOrderFragment()
        }
    }

    private val orderAdapter =
        object : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_order_status) {

            private val goodsAdapter =
                object : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_goods_order) {
                    override fun convert(holder: BaseViewHolder, item: String) {

                    }
                }

            override fun convert(holder: BaseViewHolder, item: String) {
                holder.getView<RecyclerView>(R.id.rvGoodsOrderBody)
                    .adapter = goodsAdapter.apply { setNewInstance(mutableListOf("")) }
            }
        }

    override val layoutResId: Int
        get() = R.layout.fragment_main_order

    override fun initView() {
        rvGoodsOrderBody.apply {
            val decoration = SpacingItemDecoration(
                vGap = ConvertUtils.dp2px((15f)),
                hGap = ConvertUtils.dp2px((15f))
            )
            addItemDecoration(decoration)
        }.adapter = orderAdapter

        orderAdapter.setOnItemClickListener { _, _, _ ->
            OrderDetailsActivity.open(requireActivity())
        }
    }

    override fun initData() {
        val videos: MutableList<String> = mutableListOf()
        for (index in 0..10) {
            videos.add(index.toString())
        }
        orderAdapter.setNewInstance(videos)
    }

}